package com.zy.datareceiver.binsess.decode.util;

import com.zy.datareceiver.binsess.warning.entity.WarningThreshold;
import com.zy.datareceiver.core.cast.CacheDict;


public abstract class WarningLevelUtil {

    public static WarningThreshold getLevel(Integer pointId,Integer paramterId,Double value){
        WarningThreshold res = new WarningThreshold();
        if (pointId == null || paramterId == null){
            res.setLevelId(-1);
            return res;
        }
        WarningThreshold[] warningThresholds = CacheDict.getWarningThresholdByPointIdAndParameterId(pointId,paramterId);//,.getInstance().thresholdMap.get(key);

        if (warningThresholds != null){//1级预警 >> 2级预警 >> 三级预警
            for (int i = 0; i < warningThresholds.length; i++) {//todo i有语义,表示预警级别
                WarningThreshold warn= warningThresholds[i];
                if (warn == null){
                    continue;
                }
                if (warn.getPositive() == null || warn.getNegative() == null){
                    continue;
                }
                if (warn.getPositive() < value || warn.getNegative() > value){
                    return warn;
                }
            }
        }else{
            res.setLevelId(-2); //表示是副参数
        }
        res.setLevelId(-1);// 正常数据，未触发预警
        return res;
    }
}
